package com.xc.freeapp.account.controller;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.wordnik.swagger.annotations.Api;
import com.wordnik.swagger.annotations.ApiOperation;
import com.xc.freeapp.bean.AuthInfo;
import com.xc.freeapp.exception.BaseException;
import com.xc.freeapp.service.LeadingExaminingService;
import com.xc.freeapp.util.AuthUtil;
import com.xc.freeapp.util.TokenAnnotation;
/**
 * 智能导诊模块controller
 * @author ZhouXinjie
 */
@Controller
@RequestMapping("/leadexamining")
@Api(value = "/leadexamining",description="智能导诊")
public class LeadExaminingController extends AbstractController{

	@Autowired
	private  LeadingExaminingService leadingService;
	/**
	 * 根据病症获取可能犯的疾病
	 * @param paramsmap{"sid","sidlist"}
	*/
	@TokenAnnotation(required=false)
	@RequestMapping(value = "/possibleDiseases", method = RequestMethod.GET)
	@ResponseBody 
	@ApiOperation(value = "根据病症获取可能犯的疾病")
	public  List<Map<String, Object>> getPossibleDiseases(@RequestParam("symptoms") String symptoms) throws BaseException{
		AuthInfo authInfo = AuthUtil.getAuthInfo(getRequest());
		Map<String, Object> paramsmap = new HashMap<String, Object>();
		if(symptoms.indexOf(",")<0){//只有一个sid
			paramsmap.put("sid", symptoms);
			paramsmap.put("sidList", "");
		}else{
			paramsmap.put("sid", symptoms.substring(0,symptoms.indexOf(",")));
			String[] arra = symptoms.substring(symptoms.indexOf(",")+1,symptoms.length()).split(",");
			Long[] longs = new Long[arra.length]; 
			for(int i=0;i<arra.length;i++){
				longs[i] = Long.parseLong(arra[i]);
			}
			Arrays.sort(longs);//从小到大排序
			String tonew ="";
			for(Long a :longs){
				tonew+=a+",";
			}
			tonew = tonew.substring(0,tonew.length()-1);//去掉最后一个“,”
			paramsmap.put("sidList", tonew);
		}
        List<Map<String, Object>> list = leadingService.getPossibleDiseases(paramsmap);
		return list;
	}
}
